/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.mdc.hearts.ejb.gameLogic;
import java.io.Serializable;
import static it.mdc.hearts.ejb.gameLogic.GlobalConstants.*;
/**
 *
 * @author Administrator
 */
public class Card implements Serializable, Comparable<Card>{
    
    //  Value   Name
    //  0       2
    //  1       3
    //  2       4
    //  3       5
    //  4       6
    //  5       7
    //  6       8
    //  7       9
    //  8       10
    //  9       JACK
    //  10      QUEEN
    //  11      KING
    //  12      ACE
    
    
    private final int JACK = 9;
    private final int QUEEN = 10;
    private final int KING = 11;
    private final int ACE = 12;
    
    private int seed;
    private int value;
    private int point;
    private String name;
    
    public Card() 
    {
        this.seed = -1;
        this.value = -1;
        this.name = "BLANK";
    }
    
    Card(int seed, int value) 
    {
        this.seed = seed;
        this.value = value;
        
        if(this.seed == HEARTS)
        {
            this.point = 1;
        }
        else if((this.seed == SPADES) && (this.value == QUEEN))
        {
            this.point = 13;
        }
        else
        {
            this.point = 0;
        }
    }

    @Override
    public String toString() {
        
        return getName();
    }

    int getSeed() {
        return seed;
    }

    void setSeed(int seed) {
        this.seed = seed;
    }

    int getValue() {
        return value;
    }

    void setValue(int value) {
        this.value = value;
    }

    int getPoint() {
        return point;
    }

    void setPoint(int point) {
        this.point = point;
    }

    @Override
    public int compareTo(Card o) {
        final int BEFORE = -1;
        final int EQUAL = 0;
        final int AFTER = 1;
        
        if(this.seed < o.seed)
        {
            return BEFORE;
        }
        else if(this.seed > o.seed)
        {
            return AFTER;
        }
        else
        {
            if(this.value < o.value)
            {
                return BEFORE;
            }
            else if(this.value > o.value)
            {
                return AFTER;
            }
            else
            {
                return EQUAL;
            }
        }
    }

    public String getName() {
        if((seed < 0) || (value < 0))
        {
            return "BLANK";
        }
        
        name = "";
        
        switch(value)
        {
            case JACK:
                name += "J";
                break;
            case QUEEN:
                name += "Q";
                break;
            case KING:
                name += "K";
                break;
            case ACE:
                name += "A";
                break;
            default:
                name += (value+2);
                break;
        }
        
        name += "_";
        
        switch(seed)
        {
            case HEARTS:
                name += HEARTS_NAME;
                break;
            case DIAMONDS:
                name += DIAMONDS_NAME;
                break;
            case SPADES:
                name += SPADES_NAME;
                break;
            case CLUBS:
                name += CLUBS_NAME;
                break;                
        }
        
        return name;
    }
    
}
